﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Microsoft.VisualBasic;

namespace SalePartial.Model
{

    public class XPNotificationInfo
    {
        // Methods
        public XPNotificationInfo()
        {
            this._createUserID = Guid.Empty;
            this._recipientUserID = Guid.Empty;
            this._status = string.Empty;
            this._targetID = Guid.Empty;
            this._title = string.Empty;
            this._bodyText = string.Empty;
            this._attachment = string.Empty;
            this._notifyID = Guid.NewGuid();
            this._createDate = DateTime.Now;
            this._sendDate = DateTime.MinValue.AddYears(0x76c);
            this._readDate = DateTime.MinValue.AddYears(0x76c);
            this._replyDate = DateTime.MinValue.AddYears(0x76c);
            this._lastSaveDate = DateTime.MinValue.AddYears(0x76c);
            this._targetID = Guid.Empty;
            this._contentType = 0;
            this._status = "000";
        }

        public XPNotificationInfo(SqlDataReader reader)
        {
            this._createUserID = Guid.Empty;
            this._recipientUserID = Guid.Empty;
            this._status = string.Empty;
            this._targetID = Guid.Empty;
            this._title = string.Empty;
            this._bodyText = string.Empty;
            this._attachment = string.Empty;
            this.LoadFromReader(reader);
        }

        //public XPNotificationInfo(Guid id)
        //{
        //    this._createUserID = Guid.Empty;
        //    this._recipientUserID = Guid.Empty;
        //    this._status = string.Empty;
        //    this._targetID = Guid.Empty;
        //    this._title = string.Empty;
        //    this._bodyText = string.Empty;
        //    this._attachment = string.Empty;
        //    SqlDataReader reader = XPNotificationUtility.SelectReader(id);
        //    if (reader.Read())
        //    {
        //        this.LoadFromReader(reader);
        //        reader.Close();
        //    }
        //    else
        //    {
        //        if (!reader.IsClosed)
        //        {
        //            reader.Close();
        //        }
        //        throw new ApplicationException("XPNotificationInfo does not exist.");
        //    }
        //}

        protected void LoadFromReader(SqlDataReader reader)
        {
            if ((!Information.IsNothing(reader) && !reader.IsClosed))
            {
                this._notifyID = reader.GetGuid(0);
                this._createUserID = reader.GetGuid(1);
                this._recipientUserID = reader.GetGuid(2);
                if (!reader.IsDBNull(3))
                {
                    this._createDate = reader.GetDateTime(3);
                }
                if (!reader.IsDBNull(4))
                {
                    this._sendDate = reader.GetDateTime(4);
                }
                if (!reader.IsDBNull(5))
                {
                    this._lastSaveDate = reader.GetDateTime(5);
                }
                if (!reader.IsDBNull(6))
                {
                    this._status = reader.GetString(6);
                }
                if (!reader.IsDBNull(7))
                {
                    this._readDate = reader.GetDateTime(7);
                }
                if (!reader.IsDBNull(8))
                {
                    this._replyDate = reader.GetDateTime(8);
                }
                if (!reader.IsDBNull(9))
                {
                    this._targetID = reader.GetGuid(9);
                }
                this._contentType = reader.GetInt32(10);
                this._title = reader.GetString(11);
                this._bodyText = reader.GetString(12);
                if (!reader.IsDBNull(13))
                {
                    this._attachment = reader.GetString(13);
                }
            }
        }

        // Properties
        public string Attachment
        {
            get { return this._attachment; }
            set { this._attachment = value; }
        }

        public string BodyText
        {
            get { return this._bodyText; }
            set { this._bodyText = value; }
        }

        public int ContentType
        {
            get { return this._contentType; }
            set { this._contentType = value; }
        }

        public DateTime CreateDate
        {
            get { return this._createDate; }
            set { this._createDate = value; }
        }

        public Guid CreateUserID
        {
            get { return this._createUserID; }
            set { this._createUserID = value; }
        }

        public DateTime LastSaveDate
        {
            get { return this._lastSaveDate; }
            set { this._lastSaveDate = value; }
        }

        public Guid NotifyID
        {
            get { return this._notifyID; }
            set { this._notifyID = value; }
        }

        public DateTime ReadDate
        {
            get { return this._readDate; }
            set { this._readDate = value; }
        }

        public Guid RecipientUserID
        {
            get { return this._recipientUserID; }
            set { this._recipientUserID = value; }
        }

        public DateTime ReplyDate
        {
            get { return this._replyDate; }
            set { this._replyDate = value; }
        }

        public DateTime SendDate
        {
            get { return this._sendDate; }
            set { this._sendDate = value; }
        }

        public string Status
        {
            get { return this._status; }
            set { this._status = value; }
        }

        public Guid TargetID
        {
            get { return this._targetID; }
            set { this._targetID = value; }
        }

        public string Title
        {
            get { return this._title; }
            set { this._title = value; }
        }


        // Fields
        private string _attachment;
        private string _bodyText;
        private int _contentType;
        private DateTime _createDate;
        private Guid _createUserID;
        private DateTime _lastSaveDate;
        private Guid _notifyID;
        private DateTime _readDate;
        private Guid _recipientUserID;
        private DateTime _replyDate;
        private DateTime _sendDate;
        private string _status;
        private Guid _targetID;
        private string _title;
    }


}
